package com.lh.elevator;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class ElevatorQueue {
    private List<Integer> list = new ArrayList<>();

    public void add(Integer num) {
        if (!list.contains(num)) {
            list.add(num);
            sort();
        }

    }

    public Boolean isEmpty(){
        return list.isEmpty();
    }

    /**
     * 移除元素
     * @param height 电梯所在的楼层
     * @param status 1 上升 2下降
     * @return
     */
    public Integer remove(Integer height, Integer status) {
        if (list.size() != 0) {
            if (status == 1) {
                return list.remove(0);
            }
            return list.remove(list.size()-1);

        }
        log.info("当前队列为空!");
        return -1;
    }

    public void sort() {
        list = this.list.stream().sorted(Comparator.comparing(Integer::intValue)).collect(Collectors.toList());
    }

}
